using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace NotAClue.EF.Auditing.Models.Mapping
{
    public class AuditEntryItemMap : EntityTypeConfiguration<AuditEntryItem>
    {
        public AuditEntryItemMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.ColumnName)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.OldValue)
                .IsRequired();

            this.Property(t => t.NewValue)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("AuditEntryItems");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.AuditEntryId).HasColumnName("AuditEntryId");
            this.Property(t => t.ColumnName).HasColumnName("ColumnName");
            this.Property(t => t.OldValue).HasColumnName("OldValue");
            this.Property(t => t.NewValue).HasColumnName("NewValue");

            // Relationships
            this.HasRequired(t => t.AuditEntry)
                .WithMany(t => t.AuditEntryItems)
                .HasForeignKey(d => d.AuditEntryId);

        }
    }
}
